<?php
error_reporting(E_ALL & ~E_NOTICE & E_WARNING);
$file = $_FILES['upfile'];
if (empty($file)) {
    return;
}
$ext     = end(explode('.', $file['name']));
$content = file_get_contents($file['tmp_name']);
$content = base64_encode($content);
if (empty($content)) {
    return;
}
$config        = include_once "../../../../../../Common/Conf/config.php";
$UPLOAD_DOMAIN = $config['IMG_UPLOAD_API']['DOMAIN'];
$UPLOAD_API    = $config['IMG_UPLOAD_API']['API'];
$url           = $UPLOAD_DOMAIN . $UPLOAD_API;
$options       = array(
    'http' => array(
        'method'  => 'POST',
        'header'  => 'fileext:' . $ext,
        'content' => $content,
    ),
);

$context = stream_context_create($options);
$result  = file_get_contents($url, false, $context);
if ($result) {
    $GET_DOMAIN       = $config['IMG_GET_API']['DOMAIN'];
    $GET_DIR          = $config['IMG_GET_API']['DIR'];
    $GET_DEFAULT_SIZE = $config['IMG_GET_API']['DEFAULT_SIZE'];
    $getImgUrl        = $GET_DOMAIN . $GET_DIR . $GET_DEFAULT_SIZE . $result;

    $info = array(
        'originalName' => $file['name'],
        'name'         => $file['name'],
        'url'          => $getImgUrl,
        'size'         => $file['size'],
        'type'         => '.' . $ext,
        'state'        => 'SUCCESS',
    );

    echo json_encode($info);
} else {
    return false;
}

/*header("Content-Type:text/html;charset=utf-8");
error_reporting( E_ERROR | E_WARNING );
date_default_timezone_set("Asia/chongqing");
include "Uploader.class.php";
//上传配置
$config = array(
"savePath" => "upload/" ,             //存储文件夹
"maxSize" => 1000 ,                   //允许的文件最大尺寸，单位KB
"allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" )  //允许的文件格式
);
//上传文件目录
$Path = "upload/";

//背景保存在临时目录中
$config[ "savePath" ] = $Path;
$up = new Uploader( "upfile" , $config );
$type = $_REQUEST['type'];
$callback=$_GET['callback'];

$info = $up->getFileInfo();*/

/**
 * 返回数据
 */
/*if($callback) {
echo '<script>'.$callback.'('.json_encode($info).')</script>';
} else {
echo json_encode($info);
}*/
